<?php 
	require_once('../includes/config.php');
?>
<script type="text/javascript">
$(document).ready( function() {
	//load popup to edit
	$(".edit").click(function(){
		centerPopup();
		loadPopup();
		page=$(this).attr("href");
		$("#popupProduct").html("loading...").load(page);
		return false;
	});	
	//handel delete click
	$(".del").click(function(){
		el=$(this);
		if(confirm("Are you sure?"))
		{
			$.ajax({
				url:$(this).attr("href"),
				type:"POST",
				dataType: 'json',
				success:function(data)
				{
					if(data==1)
					{
						el.parent().parent().fadeOut('slow');
					}
					else
					{
						alert(data);
					}
				}
			})
		}
		return false;
	});
});
</script>

<table id="rounded-corner">
    <thead>
    	<tr>
        	<th scope="col" class="rounded-company"></th>
            <th scope="col" class="rounded">Mã sản phẩm</th>
            <th scope="col" class="rounded">Danh mục</th>
            <th scope="col" class="rounded">Tên sản phẩm</th>
            <th scope="col" class="rounded">Ngày thêm vào</th>
            <th scope="col" class="rounded">Cập nhật lần cuối</th>
            <th scope="col" class="rounded">Sửa</th>
            <th scope="col" class="rounded-q4">Xóa</th>
        </tr>
    </thead>  
    <tbody>
    <?php
		if(isset($_GET['catid']) && $_GET['catid'] != ""){
			$catid = $_GET['catid'];
			$product_query = "SELECT * FROM tbl_product WHERE pro_cat = '$catid' ORDER BY pro_date_added DESC";
		}
		else {
			$product_query = "SELECT * FROM tbl_product ORDER BY pro_date_added DESC";
		}
		$currentPage = strstr($_SERVER['REQUEST_URI'],'index');
		$itemperPage = 20;
		$result = mysql_query(_getPagingQuery("$product_query", $itemperPage));
		$totalpage = _totalpage("$product_query", $itemperPage);
		$pages = paginate ("index.php?view=product", "page", $totalpage, $currentPage, $itemperPage);
		if(mysql_num_rows($result)>0)
		{
			while($row = mysql_fetch_assoc($result))
			{
				extract($row);					
	?>
            <tr>
                <td><input type="checkbox" name="" /></td>
                <td><?php echo $id; ?></td>
                <td><?php echo _GetCatName($pro_cat);?></td>
                <td><a target="_blank" href="../index.php?mod=product&act=detail&id=<?php echo $id; ?>"><?php echo $pro_name; ?></a></td>
                <td><?php echo $pro_date_added; ?></td>
                <td><?php if($pro_lasted_update != "") echo $pro_lasted_update; else echo "Not Avaiable";?></td>
                <td><a class="edit" href="product_f.php?act=edit&id=<?php echo $id; ?>"><img src="templates/images/user_edit.png" alt="" title="" border="0" /></a></td>
                <td><a class="del" href="product_process.php?act=del&id=<?php echo $id; ?>"><img src="templates/images/trash.png" alt="" title="" border="0" /></a></td>
            </tr>
    <?php
			} //end while
		} //end if
	?>
    </tbody>
</table>
